<template>
  <rx-layout>
    <div slot="center" style>
      <rx-fit>
        <div slot="toolheader" foldheader="true" foldbtn="true" border="false">
          <div class="table-page-search-wrapper">
            <a-form layout="inline">
              <a-row :gutter="24">
                    <a-col :span="8">
                      <a-form-item :label="i18n('recordTime','记录时间')">
                          <a-input :placeholder="i18n('recordTime','记录时间','input')" v-model="queryParam.Q_UPDATE_TIME___S_LK"/>
                      </a-form-item>
                    </a-col>
                    <a-col :span="8">
                      <a-form-item :label="i18n('version','版本')">
                          <a-input :placeholder="i18n('version','版本','input')" v-model="queryParam.Q_VERSION__S_LK"/>
                      </a-form-item>
                    </a-col>
                <template v-if="advanced">

                </template>
                <a-col :md="8" :sm="24">
              <span class="table-page-search-submitButtons">
                <a-button @click="$refs.table.loadData()" icon="search" type="primary">{{$ti18('rxList.searchBtn','查询')}}</a-button>
                <a-button @click="resetSearch" style="margin-left: 4px">{{$ti18('rxList.resetBtn','重置')}}</a-button>
                <a @click="toggleAdvanced" style="margin-left: 8px">
                  {{ advanced ? $ti18('rxList.putAwayBtn','收起') : $ti18('rxList.openBtn','展开') }}
                  <a-icon :type="advanced ? 'up' : 'down'"/>
                </a>
              </span>
                </a-col>
              </a-row>
            </a-form>
          </div>
          <div class="table-operator">
              <a-dropdown v-if="removeEnable && selectedRowKeys.length > 0">
              <a-button alias="listHistoryDelete" :butn-icon="'delete'" :butn-type="'danger'"
                         :show-no-right="false" @click="delByIds(selectedRowKeys)">{{$ti18('rxList.delBtn','删除')}}</a-button>
            </a-dropdown>

          </div>
        </div>
        <rx-grid
                ref="table"
                :allowRowSelect="true"
                :multiSelect="true"
                :columns="columns"
                :defaultPageSize="10"
                url="/api-form/form/core/listHistory/query"
                :queryParam="queryParam"
                data-field="result.data"
                :pageSizeOptions="['10','30','40']"
                id-field="id"
                @selectChange="onSelectChange"
        >
          <span slot="action" slot-scope="{ text, record }" class="actionIcons">
            <span v-if="editEnable" alias="listHistoryEdit" :show-no-right="false" @click="edit(record)">{{i18n('view','查看')}}</span>
            <span v-if="removeEnable" alias="listHistoryDelete" :show-no-right="false" @click="preview(record)">{{$ti18('rxList.preview','预览')}}</span>
          </span>
        </rx-grid>
      </rx-fit>
    </div>
  </rx-layout>
</template>

<script>
  import ListHistoryApi from '@/api/form/core/listHistory'
  import ListHistoryEdit from './ListHistoryEdit'
  import {BaseList} from "@lowcode/jpaas-common-lib";
  import SysAppApi from "@/api/system/core/sysApp";
  import {openUrl} from "@/utils/util";

  export default {
    name: 'ListHistoryList',
    mixins: [BaseList],
    props:["layerid","destroy","listId","keyId"],

    data() {
      return {
        columns: [
          {
            title: this.$ti18('rxList.index','序号'),
            type: 'indexColumn',
            width: 100,
            dataIndex: 'serial',
            scopedSlots: {customRender: 'serial'}
          },
          {title: this.i18n('version','版本'), dataIndex: 'version', width: 100},
          {title: this.i18n('recordTime','记录时间'), dataIndex: 'updateTime', width: 100},
          {title: this.$ti18('rxList.action','操作'), width: 100, dataIndex: 'action', scopedSlots: {customRender: 'action'}}
        ],
        component:ListHistoryEdit,
        comment:this.i18n('comment','列表变更历史'),
        widthHeight:['800px','600px']
      }
    },

    created() {
      this.queryParam['Q_LIST_ID__S_EQ'] = this.listId;
    },
    methods:{
      i18n(name,text,key){
          return this.$ti18(name,text,"ListHistory",key);
      },
      delById(ids){
        return ListHistoryApi.del({ ids: ids.join(',') });
      },
      getListByParams(parameter){
        return ListHistoryApi.query(parameter)
      },
      resetSearch(){
          var Q_LIST_ID__S_EQ=this.queryParam.Q_LIST_ID__S_EQ;
          delete this.queryParam
          this.$nextTick(() => {
              this.queryParam = {Q_LIST_ID__S_EQ};
              let appId=this.curApp.appId;
              if(this.hasAppId && appId){
                  this.queryParam.Q_APP_ID__S_EQ=appId;
              }
              this.$refs[this.table].loadData();
          })
      },
      preview(record){
        let appId=record.appId;
        SysAppApi.get(appId).then(res=>{
          let app=res.data;
          let path=app.path;
          let url=`${path}/${app.clientCode}/list/${record.key}?appId=${appId}`;
          let title=record.name;
          openUrl({url:url,title:title,curVm:this,max:true});
        })
      },
    }
  }
</script>
<style scoped>

</style>

